﻿using System;
using System.Text;

namespace System.Net
{
    /// <summary>
    /// 网络帮助类
    /// </summary>
    public class NetworkHelper
    {
        /// <summary>
        /// 获取本机IP地址集合
        /// </summary>
        /// <returns></returns>
        public static System.Collections.Generic.List<System.Net.IPAddress> GetIPv4NetworkInterfaces()
        {
            System.Collections.Generic.List<System.Net.IPAddress> list = new System.Collections.Generic.List<System.Net.IPAddress>();
            foreach (System.Net.NetworkInformation.NetworkInterface interface2 in System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces())
            {
                if (((interface2.NetworkInterfaceType != System.Net.NetworkInformation.NetworkInterfaceType.Loopback) && (interface2.OperationalStatus == System.Net.NetworkInformation.OperationalStatus.Up)) && interface2.Supports(System.Net.NetworkInformation.NetworkInterfaceComponent.IPv4))
                {
                    foreach (System.Net.NetworkInformation.UnicastIPAddressInformation information in interface2.GetIPProperties().UnicastAddresses)
                    {
                        if (information.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                        {
                            list.Add(information.Address);
                        }
                    }
                }
            }
            return list;
        }
    }
}
